### Libraries ###
library(tidyverse)
library(tidytuesdayR)
library(here)
library(plotly)
library(scales)
library(htmlwidgets)
rm(list=ls())
### Bring in Data ###
tuesdata <- tt_load(2021, week = 7)
##
## Downloading file 1 of 11: `home_owner.csv`
## Downloading file 2 of 11: `income_aggregate.csv`
## Downloading file 3 of 11: `income_distribution.csv`
## Downloading file 4 of 11: `income_limits.csv`
## Downloading file 5 of 11: `income_mean.csv`
## Downloading file 6 of 11: `income_time.csv`
## Downloading file 7 of 11: `lifetime_earn.csv`
## Downloading file 8 of 11: `lifetime_wealth.csv`
## Downloading file 9 of 11: `race_wealth.csv`
## Downloading file 10 of 11: `retirement.csv`
## Downloading file 11 of 11: `student_debt.csv`
race_wealth <- tuesdata$race_wealth
### Data Analysis ###
glimpse(race_wealth)
## Rows: 96
## Columns: 4
## $ type <chr> "Average", "Average", "Average", "Average", "Average", "…
## $ year <dbl> 1963, 1963, 1963, 1963, 1983, 1983, 1983, 1983, 1989, 19…
## $ race <chr> "Non-White", "White", "Black", "Hispanic", "Non-White", …
## $ wealth_family <dbl> 19503.84, 140632.66, NA, NA, 73233.62, 324057.60, 67269.…
static<-race_wealth %>%
ggplot(aes(x=year, y=wealth_family,
color=race, fill=race)) +
geom_bar(stat="identity", position="dodge", aes(color = race)) +
labs(color="Race", fill = "Race",
x="Year", y="Average Family Wealth per Year") +
theme_bw()
race_wealth %>%
plot_ly(x=~year, y=~wealth_family,
color=~race, fill=~race,
type = "bar",
text = ~paste0("Annual Family Income: $", # customize hover label text
comma(round(wealth_family),decimals = 2)),
hovertemplate = paste('%{text}')) %>%
layout(title = "Annual Family Income", #change plot title
xaxis = list(title = "Year"), #change x-axis title
yaxis = list(title = "Annual Income (USD)")) #change y-axis title